<%@ page language="java" pageEncoding="UTF-8"
	import="com.lyk.swap.orm.Product,com.lyk.swap.RiskProfit"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Add Swap</title>

<link rel="stylesheet" type="text/css" href="ms.css">
<link rel="stylesheet" type="text/css" href="mshome.css">
<link rel="stylesheet" type="text/css" href="mstop.css">

<logic:notPresent name="userid" scope="session">
	<logic:redirect page="/user_error.jsp" />
</logic:notPresent>
<logic:notPresent name="productlist" scope="session">
	<logic:redirect page="/error.jsp" />
</logic:notPresent>
</head>
<body>
	<center>
		<div class="n_topNavBg">
			<div class="n_topNav">
				<div id="topBanner">
			    	<div id="logoAndLinks">
			        	<a href="http://www.morganstanley.com" id="logo">
			            	<img src="img/logo-ms.gif" border="0" alt="Morgan Stanley">
			            </a>
			            <div id="topNavMod">
			            	<div align="right">
			                </div>
			            </div>
			        </div>
			    </div>
			</div>
		</div>
		<div class="n_bnrContainer">
			<div class="n_bnrBg" id="n_bannerBg">
				<html:form action="/addTrade">
						product : <html:select property="product" styleId="product">
						<logic:iterate id="product" name="productlist" scope="session">
							<html:option value="<%=((Product) product).getCode()%>">
								<bean:write name="product" property="code" />
							</html:option>
						</logic:iterate>
					</html:select>
					<br />
						buy/sell : <html:select property="buy" styleId="buy">
						<html:option value="true">BUY</html:option>
						<html:option value="false">SELL</html:option>
					</html:select>
					<br />
						price : <html:text property="price" styleId="price" />
					<html:errors property="price" />
					<br />
						quantity : <html:text property="quantity" styleId="quantity" />
					<html:errors property="quantity" />
					<br />
						start : <html:text property="start" styleId="start" />
					<html:errors property="start" />
					<br />
						end : <html:text property="end" styleId="end" />
					<html:errors property="end" />
					<br />
						counterparty : <html:text property="counterparty"
						styleId="counterparty" />
					<html:errors property="counterparty" />
					<br />
						settlement : <html:select property="settlement">
						<html:option value="monthly">monthly</html:option>
					</html:select>
					<html:submit />
					<html:cancel />
				</html:form>
				<logic:present name="rp" scope="session">
					<%
						RiskProfit rp = (RiskProfit) session.getAttribute("rp");
					%>
					<script type="text/javascript">
						var product = document.getElementById("product");
						var buy = document.getElementById("buy");
						document.getElementById("price").value =
					<%=rp.getPrice()%>
						;
						document.getElementById("quantity").value =
					<%=rp.getQuantity()%>
						;
						document.getElementById("start").value =
					"<%=rp.getFormatStart()%>"
						;
						document.getElementById("end").value =
					"<%=rp.getFormatEnd()%>"
						;
						document.getElementById("counterparty").value =
					"<%=rp.getCounterparty()%>"
						;
						var buyvalue =
					<%=rp.getBuy()%>
						;
						if (buyvalue) {
							buy.selectedIndex = 0;
						} else {
							buy.selectedIndex = 1;
						}
						for ( var i = 0; i < product.options.length; i++) {
							if (product.options[i].value ==
					"<%=rp.getProduct().getCode()%>"
						) {
								product.selectedIndex = i;
								break;
							}
						}
					</script>
				</logic:present>
			</div>
		</div>
		<div class="n_footerBg" id="footer">
			<div class="n_footer">
		    	By ISAD-SJTU. Author Yizhi Gu, Yunkai Luo and Rui Shi.
		    </div>
		</div>
	</center>
	</body>
</html>

